/**
 * 所有关于用户模块的数据请求
 */

//  导入自己处理过的axios
import request from '@/utils/request'
// 导入工具方法
// import { getItem } from '@/utils/storage'

/**
 * 登录注册
 * @param {*} data  登录数据
 */
export const userLogin = data=>{
    return request({
        url:'/v1_0/authorizations',
        method:'post',
        data
    })
}
/**
 * 获取手机验证码
 * @param {*} mobile 
 */
export const getPhoneSms =mobile=>{
    return request({
        url:`/v1_0/sms/codes/${mobile}`,
        method:'get'
    })
}
/**
 * 获取用户资料
 */
export const getUserInfo = ()=>{
    // const user = getItem('TOUTIAO_USER')
    return request({
        url:'/v1_0/user',
        // // 请求头配置
        // headers:{
        //     Authorization:`Bearer ${user.token}`
        // }
    })
}

/**
 * 获取用户资料
 */
export const getUserInfoDetail = ()=>{
  return request({
      url:'/v1_0/user/profile',
     
  })
}

/**
 * 更新用户头像
 */
export function updateUserPhoto (data) {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}
/**
 * 更新用户资料（昵称，性别，生日）
 */
export function updateUserInfo (data) {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}

/**
 * 关注用户
 * @param {*} target  被关注用户id
 */
export const addFollow = target =>{
    return request({
        url:'/v1_0/user/followings',
        method:'post',
        data:{
            target
        }
    })
}
/**
 * 取消关注用户
 * @param {*} target  被取消关注用户id
 */
export const deleteFollow = target =>{
    return request({
        url:`/v1_0/user/followings/${target}`,
        method:'DELETE',
    })
}

/**
 * 收藏文章
 */
export const addCollect = target => {
    return request({
      method: 'POST',
      url: '/v1_0/article/collections',
      data: {
        target
      }
    })
  }
  
  /**
   * 取消收藏文章
   */
  export const deleteCollect = target => {
    return request({
      method: 'DELETE',
      url: `/v1_0/article/collections/${target}`
    })
  }


  /**
 * 点赞
 */
export const addLike = articleId => {
    return request({
      method: 'POST',
      url: '/v1_0/article/likings',
      data: {
        target: articleId
      }
    })
  }
  
  /**
   * 取消点赞
   */
  export const deleteLike = articleId => {
    return request({
      method: 'DELETE',
      url: `/v1_0/article/likings/${articleId}`
    })
  }